import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Image, Text } from "@tarojs/components-rn";
import { toJS } from 'mobx';
import { inject, observer } from "@tarojs/mobx-rn";
import { getRuntime, pageSize, partOf } from "../../utils/common";
import welfare_recordStyleSheet from "./welfare_record_styles";
var _styleSheet = welfare_recordStyleSheet;
let WelfareRecord = class WelfareRecord extends Component {
  constructor(props) {
    super(props);
    this.state = {
      pageIndex: 1,
      pageSize,
      items: [],
      totalCount: 0
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '资助记录' });
    this.getAllUserCrowdFunding();
  }
  getAllUserCrowdFunding() {
    let { pageIndex, pageSize } = this.state;
    let { userStore } = this.props.stores;
    userStore.getAllUserCrowdFunding({
      pageIndex,
      pageSize,
      callback: res => {
        if (pageIndex === 1) {
          this.setState({ totalCount: toJS(res.totalCount), items: toJS(res.items) });
        } else {
          const { items } = this.state;
          items.push(...(res.items || []));
          this.setState({ totalCount: res.totalCount, items });
        }
      }
    });
  }
  onReachBottom() {
    let { totalCount, pageSize, pageIndex } = this.state;
    const { loading } = this.props.stores.homeStore;
    if (totalCount > pageIndex * pageSize && !loading) {
      this.setState({
        pageIndex: pageIndex + 1
      }, () => {
        this.getAllUserCrowdFunding();
      });
    }
  }
  handelRouter(url = '/pages/index/index') {
    getRuntime().navigateTo(url);
  }
  render() {
    let { items } = this.state;
    return <View style={_styleSheet["welfare-index"]}>
        {items.length > 0 && <View style={_styleSheet["list-16"]}>
          {items.map(item => {
          return <View onClick={this.handelRouter.bind(this, '/pages/public_welfare/welfare_record_detail?id=' + item.id)} style={_styleSheet["list-16-item"]}>
                  <Image src={item.logoImg} style={_styleSheet["img"]} />
                  <View style={_styleSheet["info"]}>
                    <View style={_styleSheet["list-title"]}>{item.name}</View>
                    <View style={_styleSheet["list-desc"]}>{partOf(item.introduce, 50)}</View>
                    <View style={_styleSheet["price"]}>捐助金额：
                      <Text style={[_styleSheet["list-small"], _styleSheet["color-orange"]]}>￥</Text>
                      <Text style={[_styleSheet["list-price"], _styleSheet["color-orange"]]}>{item.actualAmount}</Text>
                    </View>
                  </View>
                </View>;
        })}
        </View>}
        {items.length <= 0 && <View style={_styleSheet["page-none-info"]}>您还没有公益记录哦~</View>}
      </View>;
  }
};
WelfareRecord = tslib_1.__decorate([inject("stores"), observer], WelfareRecord);
export default WelfareRecord;